﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class MembershipCard_Ticket_quanlist : WeiPage
{
    TicketBO tbo = new TicketBO();
    PersonInfoBO fbo = new PersonInfoBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request.QueryString["code"] != null)
            {
                try
                {
                    string url = string.Format(@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + GetAppid() + "&secret="+GetSecret()+"&code={0}&grant_type=authorization_code", Request.QueryString["code"].ToString());
                    string token = PostRequest(url);
                    if (token.Contains("7200"))
                    {
                        string[] b = token.Split('\"');
                        Session["FromUserName"] = b[13];
                        Session["ToUserName"] = GetAppid();
                        // Response.Write(b[13]);
                    }
                }
                catch (Exception)
                {

                }
            }
            if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
            {
                string user = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
                string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
                Session["FromUserName"] = user;
                Session["ToUserName"] = user2;
                PersonInfo per = fbo.GetModel(user);
                if (per != null)
                {
                }
            }

            List<Ticket> list = tbo.GetModelList("  IsShow=1 AND EndDate>GETDATE() ");
            nr.InnerHtml = "";
            foreach (Ticket m in list)
            {
                nr.InnerHtml += string.Format(@" <a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8ecea9aaa3d6162b&redirect_uri=http://m.shanghaivive.com.cn/Herborist/MembershipCard/Ticket/quandetail.aspx?id={3},0&response_type=code&scope=snsapi_base&state=STATE&from=singlemessage&isappinstalled=0#wechat_redirect'><li class='{2}'>
          <div class='quanleft'>
           <div class='quancon'>
           <!-- <p>{0}</p>
            <p><strong>{4}</strong>折  <span>原价：{5}元</span></p>
            <p>&nbsp;</p>-->
<img src='{7}' />
          </div>
          </div>
           <div class='quanright'>
            <div class='quanbottom'>
             <p>有效期至<br>
             {1}</p>
             </div>
             <div class='quanbottom'>
               <p>已领取<strong>{6}</strong>份</p>
               </div>
           </div>
        </li></a>", m.Name, DateTime.Parse(m.EndDate.ToString()).ToString("yyyy-MM-dd"), m.Type == "抵扣券" ? "diyong" : m.Type == "现金券" ? "xianjin" : "tejiaquan",m.ID,m.Discount,Convert.ToInt32(m.OldPrice),m.HavNum,m.Remark);
            }

        }
    }
}